package com.bm.util;


import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author LENOVO
 */
public class MacAddressReader {
    private static InetAddress clientIPAddress;
    
    public static void getIpAddress(){
        try {
            clientIPAddress = InetAddress.getLocalHost();           
        } catch (UnknownHostException ex) {
            
        }       
    }
    
    public static String getMacAddress(){
        try {
            getIpAddress();
            NetworkInterface network = NetworkInterface.getByInetAddress(clientIPAddress);
            byte[] mac = network.getHardwareAddress();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < mac.length; i++) {
                sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));		
            }
            return sb.toString();
        } catch (SocketException ex) {
            
        }
        return null;        
    }
}
